#coding:utf8
import cherrypy
_js = """
        <script type="text/javascript">
            $(function()
            {
                //登录
                $('#loginbut').click(function()
                {
                    var user = $('#usrtext').attr("value");
                    var pwd = $('#pwdtext').attr("value");
                    
                    var xmlhttp;
                    if (window.XMLHttpRequest)
                    {// code for IE7+, Firefox, Chrome, Opera, Safari
                      xmlhttp=new XMLHttpRequest();
                    }
                    else
                    {// code for IE6, IE5
                      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }

                    xmlhttp.onreadystatechange=function()
                    {
                      if (xmlhttp.readyState==4 && xmlhttp.status==200)
                        {
                            if(xmlhttp.responseText)
                            {
                                alert(xmlhttp.responseText);
                            }
                            else
                            {
                                window.location.href="/sbxx";
                            }
                        }
                    }
                    xmlhttp.open("GET","login/yhdl?user="+user+"&pwd="+pwd,true);
                    xmlhttp.send();
                });

                //光标默认停在用户名处
                $('#usrtext').focus();
                
                //输入用户名回车后光标停在密码框处
                $('#usrtext').keydown(function(e){
                    if(e.keyCode==13){
                        $('#pwdtext').focus();
                    }
                });
                
                //接着输入密码后回车执行登录按钮点击事件
                $('#pwdtext').keydown(function(e){
                    if(e.keyCode==13){
                        $('#loginbut').click();
                    }
                });
            });
        </script>
"""
def login():
    return """
       <DIV class=rbroundbox>
            <DIV class=rbtop>
                <DIV>
                </DIV>
            </DIV>
            <H5>
                <form id="form1" method="post" action="javascript:void(0);">
                    <p align="center">
                        登录
                        <br>
                        用户名:
                        <input id="usrtext" type="text" maxlength="60" />
                        <br>
                        密　码:
                        <input id="pwdtext" type="password" maxlength="60" />
                        <br>
                        <input type="button" id="loginbut" value="登录" /><guest class="hint hint--right hint--info hint--always" data-hint="不输入用户名点击也可登录" ></guest>
                    </p>
                </form>
            </H5>
            <DIV class=rbbot>
            </DIV>
        </DIV>
        """
class Login:
    @cherrypy.expose
    def yhdl(self,user,pwd):
        cherrypy.session['user'] = user